import os
import tkinter
from tkinter import *
from PIL import Image, ImageTk
from main import Business, CONSTANT


# 生成资源文件目录访问路径
def resource_path(relative_path):
    if getattr(sys, 'frozen', False):  # 是否Bundle Resource
        base_path = sys._MEIPASS
    else:
        base_path = os.path.abspath(".")
    return os.path.join(base_path, relative_path)


app = tkinter.Tk()
app.title(CONSTANT.TKINTER_APPLICATION_TITLE_NAME)
# 设置窗口大小 语法：tkinter(已用root代替).geometry("长x高")
app.geometry('800x600+400+200')
width = app.winfo_screenwidth()

# 放置图像
filename = resource_path(os.path.join("res", "img2.jpg"))
load = Image.open(filename)  # 我图片放桌面上
# load = Image.open('D:\\tmp\\image 207.png')

# load.resize((width,250))
render = ImageTk.PhotoImage(load)
img = tkinter.Label(app, image=render)
img.image = render
img.place(x=80, y=0)

# label标签  :微信昵称
weChatLabel = tkinter.Label(app, text=CONSTANT.TKINTER_LABEL_CHAT)
weChatLabel.place(x=100, y=370)
var_chat = tkinter.StringVar()
chatEntity = tkinter.Entry(app, textvariable=var_chat)
chatEntity.place(x=160, y=370)

# label ：QQ昵称
qqLabel = tkinter.Label(app, text=CONSTANT.TKINTER_LABEL_TIME)
qqLabel.place(x=100, y=400)
var_qqNickName = tkinter.StringVar()
qqEntity = tkinter.Entry(app, textvariable=var_qqNickName)
qqEntity.place(x=160, y=400)

# label标签 :电话号码
phoneLabel = tkinter.Label(app, text=CONSTANT.TKINTER_LABEL_PHONE)
phoneLabel.place(x=300, y=370)
var_phone = tkinter.StringVar()
phoneEntity = tkinter.Entry(app, textvariable=var_phone)
phoneEntity.place(x=360, y=370)

# 用户昵称
uuidLabel = tkinter.Label(app, text=CONSTANT.TKINTER_LABEL_NICKNAME)
uuidLabel.place(x=300, y=400)
var_uuid = tkinter.StringVar()
uuidEntity = tkinter.Entry(app, textvariable=var_uuid)
uuidEntity.place(x=360, y=400)

infomaton = tkinter.Text(app, height=10, width=100, insertbackground='red', selectborderwidth=2, wrap=WORD)
infomaton.place(x=50, y=440)
infomaton.tag_config('tag', foreground='red')  # 设置tag即插入文字的大小,颜色等

infomaton.insert(INSERT, CONSTANT.TKINTER_CONTENT_TOAST)


# infomaton.insert(INSERT,CONSTANT.TKINTER_VARCHAR_INDEXNAME)
def confirm():
    infomaton.delete('1.0', 'end')
    user_uuid = var_uuid.get()
    # if user_nickName:
    #     infomaton.insert(INSERT, CONSTANT.TKINTER_NONE_CONTENT_TOAST)
    '''
    description: delete user information for  phone
    '''
    user_phone = var_phone.get()
    if user_phone:
        info = Business(phone=user_phone).getAccountBusiness()
        if not info:
            info = CONSTANT.TKINTER_INFO_INPUT_CORRECT_VALUE
        if not re.match(r"^1[3|4|5|7|8][0-9]{9}$", user_phone):
            info = CONSTANT.TKINTER_INFO_CONFIRM_CORRECT_VALUE
        infomaton.insert(INSERT, info)
    elif not user_uuid:
        info = CONSTANT.TKINTER_INFO_INPUT_CORRECT_EMPTY
        infomaton.insert(INSERT, info)
        return
    if user_uuid:
        Business().delBusinessByID(user_uuid)
        infomaton.insert(INSERT, CONSTANT.TOAST_FOR_DELTE_INFORMATION_RECORDER)
        pass

# 只可用以查询微信昵称 进行删除
def inquire():
    infomaton.delete('1.0', 'end')
    user_chat = var_chat.get()
    user_qq = var_qqNickName.get()
    if user_chat:
        info = Business(wechat=user_chat).getWeChatBusiness()
        if not info:
            infomaton.insert(INSERT, CONSTANT.TKINTER_INFO_USER_CHAT_INPUT_EMPTY_RECORD)
            return
        infomaton.insert(INSERT, info)
    elif not user_qq:
        info = CONSTANT.TKINTER_INFO_USER_CHAT_INPUT_CORRECT_EMPTY
        infomaton.insert(INSERT, info)
        return

    if user_qq:
        info = Business(qq=user_qq).getQQBusiness()
        if not info:
            infomaton.insert(INSERT, CONSTANT.TKINTER_INFO_USER_QQ_INPUT_EMPTY_RECORD)
            return
        infomaton.insert(INSERT, info)
    # elif not user_qq:
    #     info = CONSTANT.TKINTER_INFO_USER_CHAT_INPUT_CORRECT_EMPTY
    #     infomaton.insert(INSERT, info)
    #     return


confirmBt = tkinter.Button(app, text=CONSTANT.TKINTER_CONFIRM_CLEAN, command=confirm, activeforeground='red',
                           background='DarkCyan', height='1',
                           width='6')
confirmBt.place(x=510, y=360)

queryfirmBt = tkinter.Button(app, text=CONSTANT.TKINTER_CONFIRM_SELECT, command=inquire, activeforeground='red',
                             background='DarkCyan', height='1',
                             width='6')
queryfirmBt.place(x=510, y=400)

# fm2_center = Frame(fm2, bg='blue')
# fm2_right = Frame(fm2_left, bg='yellow')

app.mainloop()
# Entry的第一个参数是父窗口，即这里的window
# *表示输入的文本变为星号，在Entry不可见内容，若为None则表示为输入文本以原形式可见

'''
b1=tkinter.Button(root,text='insert point',width=15,height=2,command=insert_point)
b1.pack()
t=tkinter.Text(root,height=2)     #这里设置文本框高，可以容纳两行
t.pack()
        '''
'''
load = Image.open('img2.jpg')  # 我图片放桌面
render = ImageTk.PhotoImage(load)
img = tkinter.Label( image=render)
img.image = render
img.place(x=0, y=0)
'''

'''
class Application(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.window_init()
        self.createWidgets()

    def window_init(self):
        self.master.title('welcome to video-captioning system')
        self.master.bg = 'black'
        # 设置窗口的左上角标题文字 标题文字随意

        self.master.title('A刑事犯罪质量调查科清除账号GUI')
        # 设置窗口大小 语法：tkinter(已用root代替).geometry("长x高")


        self.master.geometry('800x600+400+200')

    def createWidgets(self):
        e = self.tk.Entry(self,show='*')
        e.pack()
'''

if __name__ == '__main__':
    pass
